<?php

namespace App\Admin\Actions\Post;

use App\Models\StoreUser;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class FreezeStore extends RowAction
{
    public $name = '冻结';

    public function handle(Model $model)
    {
        $status = $model->status;
        if (!in_array($status, [0, 1])) {
            return $this->response()->error('不可执行该操作！')->refresh();
        }

        $sid = $model->sid;
        $res = StoreUser::where('sid', $sid)->update(['status' => -1]);
        if ($res) {
            return $this->response()->success('操作成功！')->refresh();
        } else {
            return $this->response()->error('操作失败！')->refresh();
        }
    }

    public function dialog()
    {
        $this->confirm('确定冻结该商家吗？');
    }

}
